#ifndef NANE_MODULEMANAGERIMPL__H
#   define NANE_MODULEMANAGERIMPL__H

#   include "nane/core/crt/ModuleManager.h"
#   include "nane/core/crt/Module_.h"
#   include <vector>
#   include <cstring>

namespace nane
{
    class ModuleManager::Implementation
        : public IModuleSystem
    {
    public:
        Implementation();
        ~Implementation();

        bool Initialize();
        void Shutdown();
        bool RegisterStaticModule( const ModuleInfo* _moduleInfo );
        IModule* LoadModule( const char* _moduleName );
        IModule* GetModuleByInterface( const char* _interfaceName );
        void ForeachModule( const char* _interfaceName, ModuleApplyBase* _functor );
        
        void Release( Module* _module );
        
    public:
        struct FindModule
        {
            const char* m_name;
            FindModule( const char* _name )
                : m_name( _name )
            {

            }

            bool operator()( const ModulePtr& _modulePtr )
            {
                return std::strcmp(m_name, _modulePtr->GetName()) == 0;
            }
        };

        struct FindModuleInterface
        {
            const char* m_interfaceName;
            FindModuleInterface( const char* _interfaceName )
                : m_interfaceName( _interfaceName )
            {

            }

            bool operator()( const ModulePtr& _modulePtr )
            {
                return std::strcmp(m_interfaceName, _modulePtr->GetInfo()->interfaceName) == 0;
            }
        };

    public:
        typedef std::vector<ModulePtr> TModuleImplVector;
        TModuleImplVector modules;
    };
}   // namespace nane

#endif	// NANE_MODULEMANAGERIMPL__H
